package com.lge.clock.worldclock.cities;

import java.util.Locale;

import com.lge.clock.worldclock.util.Log;

import android.graphics.Rect;

/**
 * @author lge.com
 */
public class CityInformation extends Object implements Cloneable{
    public static final String LANGUAGE_MODE_KOREAN = "ko";
    public static final String LANGUAGE_MODE_ENGLISH = "en";
    public static final String LANGUAGE_MODE_DEFAULT = LANGUAGE_MODE_ENGLISH;
    
	public static final String HANGUL_BEGIN_UNICODE = "\uAC00";
	public static final String HANGUL_END_UNICODE = "\uD7A3";
	public static final String HANGUL_JAMO_BEGIN_UNICODE = "\u3131";
	public static final String HANGUL_JAMO_END_UNICODE = "\u314E";
	public static final String HANGUL_PARENRHESIS_START_UNICODE = "\u0028";
	public static final String HANGUL_PARENRHESIS_END_UNICODE = "\u0029";
    
    public static final int DISPLAY_LEVEL_1 = 1;
    public static final int DISPLAY_LEVEL_2 = 2;
    public static final int DISPLAY_LEVEL_3 = 3;
    public static final int DISPLAY_LEVEL_4 = 4;
    
    private static String sLanguageMode = "en";
    
    private static final String[] SUPPORTEDLOCALE = {
         "en",
         "en_US",
         "en_AU",
         "en_CA",
         "en_IE",
         "ko",
         "bg",
         "hr",
         "cs",
         "do",
         "nl",
         "nl_BE",
         "fi",
         "fr",
         "fr_BE",
         "fr_CH",
         "de",
         "de_CH",
         "el",
         "hu",
         "is",
         "it",
         "it_CH",
         "mk",
         "no",
         "pl",
         "pt",
         "ro",
         "sr",
         "sk",
         "sl",
         "es",
         "sv",
         "tr",
         "ru",
         "ru_rIL",
         "ar",
         "iw",
         "zh_CN",
         "zh_TW",
         "pt_BR",
         "es_rMX",
         "fr_CA",
         "zh_HK",
         "ms",
         "id",
         "th",
         "vi",
         "fa",
         "ja",
         "es_AR",  //[suhaeng.lee] add language es_AR for VIVO
         "kk",
         "uk"
    };
    
    private int mId;
    private String mEnglishCountry;
    private String mEnglishCity;
    private String mCountry;
    private String mCity;
    private String mLatitude;
    private String mLongitude;
    private String mRequest;
    private String mGmtString;
    private int mGmtValue;
    private int mIsSetted;
    private int mSettedTime;
    private int mSummerTime;
    private int mDisplayLevel;
    private int mLabelPosition;
    private boolean mIsDisplaySetted;
    private boolean mIsChecked;
    private boolean mIsDuplicated;
    private int mUpdateMode;
    
    private float mCoordinateX;
    private float mCoordinateY;
    private float mCoordinateZ;
    
    private Rect mWindowRect;
    
    private float mWindowX;
    private float mWindowY;

    public CityInformation(int id) {
        mId = id;
    }
    
    public CityInformation() {
    	
    }
    
    public void setID(int id) {
    	mId = id;
    }
    
    public int getID() {
        return mId;
    }

    public static String languageMode() {
        sLanguageMode = Locale.getDefault().toString();
        return sLanguageMode;
    }

    public static void languageMode(String mode) {
		String languageMode = "en";
		
		for(String str : SUPPORTEDLOCALE) {
			if(str.equals(mode)) {
				languageMode = mode;
				break;
			}
		}
				
        sLanguageMode = languageMode;
    }
    
    public static String getLanguageMode() {
        return sLanguageMode;
    }

	public static boolean isHangul(String word) {
		boolean isHangul = false;
		final boolean isLocaleKorean = 
					Locale.getDefault().getLanguage().equals("ko")
					? true : false;
		final String token = (word.length() > 1) ? word.substring(0, 1) : word;
	
		if(isLocaleKorean) {
			if ((token.compareTo(HANGUL_BEGIN_UNICODE) >= 0)
					&& (token.compareTo(HANGUL_END_UNICODE) <= 0)) {
				isHangul = true;
			}
			if ((token.compareTo(HANGUL_JAMO_BEGIN_UNICODE) >= 0)
					&& (token.compareTo(HANGUL_JAMO_END_UNICODE) <= 0)) {
				isHangul = true;
			}
		}

		return isHangul;
	}
	
	public static boolean isEnglish(String word) {
		byte[] bytes = word.getBytes();
    	if(bytes.length > 0 && ((65 <= bytes[0] && bytes[0] <= 90)
    			|| (97 <= bytes[0] && bytes[0] <= 122))){
            return true;
    	}
    	else {
    		return false;
    	}
	}
    
    public void setCityName(String city) {
    	mCity = city;
    }
    
    public String getCityName() {
        return mCity;
    }

    public void setCountryName(String country) {
    	mCountry = country;
    }
    
    public String getCountryName() {
        return mCountry;
    }
    
    public String getEnglishCityName() {
        return mEnglishCity;
    }

    public String getEnglishCountryName() {
        return mEnglishCountry;
    }
    
    public void setEnglishName(String name) {
        mEnglishCity = name;
    }

    public void setEnglishCountryName(String name) {
        mEnglishCountry = name;
    }

    public String getRequest() {
        return mRequest;
    }
    
    public void setRequest(String value) {
        mRequest = value;
    }
    
    public String getGmtString() {
        return mGmtString;
    }
    
    public void setGmtString(String value) {
        mGmtString = value;
    }
    
    public int getGmtValue() {
        return mGmtValue;
    }
    
    public void setGmtValue(int value) {
        mGmtValue = value;
    }
    
    public int getSummerTime() {
        return mSummerTime;
    }
    
    public void setSummerTime(int value) {
        mSummerTime = value;
    }
    
    public int getUpdateMode() {
    	return mUpdateMode;
    }
    
    public void setUpdateMode(int value) {
    	mUpdateMode = value;
    }
    
    public int getSettedTime() {
        return mSettedTime;
    }
    
    public void setSettedTime(int value) {
    	mSettedTime = value;
    }
        
    public String getLatitude() {
        return mLatitude;
    }
    
    public void setLatitude(String latitude) {
        mLatitude = latitude;
    }
    
    public String getLongitude() {
        return mLongitude;
    }
    
    public void setLongitude(String longitude) {
        mLongitude = longitude;
    }
    
    public float getX() {
        return mCoordinateX;
    }

    public void setX(float x) {
        mCoordinateX = x;
    }

    public void setY(float y) {
        mCoordinateY = y;
    }
    
    public float getY() {
        return mCoordinateY;
    }

    public void setZ(float z) {
        mCoordinateZ = z;
    }

    public float getZ() {
        return mCoordinateZ;
    }
    
    public void setDisplayLevel(int level) {
        mDisplayLevel = level;
    }
    
    public int getDisplayLevel() {
        return mDisplayLevel;
    }
    
    public void setWindowRect(int left, int top, int right, int bottom) {
    	if(mWindowRect == null) {
    		mWindowRect = new Rect(left, top, right, bottom);
    	}
    	else {
    		mWindowRect.set(left, top, right, bottom);
    	}
    }
    
    public Rect getWindowRect() {
    	return mWindowRect;
    }
    
    
    public void setWindowX(float x) {
        mWindowX = x;
    }
    
    public float getWindowX() {
        return mWindowX;
    }
    
    public void setWindowY(float y) {
        mWindowY = y;
    }
    
    public float getWindowY() {
        return mWindowY;
    }
    
    public void setDisplaySetting(boolean isSetting) {
        mIsDisplaySetted = isSetting;
    }
    
    public boolean isDisplaySetting() {
        return mIsDisplaySetted;
    }
    
    public void setRegistValue(int set_value) {
        mIsSetted = set_value;
    }
    
    public int getRegistValue() {
        return mIsSetted;
    }

    public void setLabelPosition(int position) {
        mLabelPosition = position;
    }
    
    public int getLabelPosition() {
        return mLabelPosition;
    }
    
    public void toggleCheckedStatus() {
        if(mIsChecked == true) mIsChecked = false;
        else mIsChecked = true;
    }
    
    public void setChecked(boolean isSetting) {
        mIsChecked = isSetting;
    }
    
    public boolean getChecked() {
        return mIsChecked;
    }
    
    public void setDuplicated(boolean isSetting) {
        mIsDuplicated = isSetting;
    }
    
    public boolean getDuplicated() {
        return mIsDuplicated;
    }

	public static String getCurrentLocale() {
		Locale current_locale = Locale.getDefault();
		String retString = "en";
		Boolean localeFound = false;
		Log.message("getCurrentLocale == " + current_locale.toString());
		for(String str : SUPPORTEDLOCALE) {
			if(str.equals(current_locale.toString())) {
				retString = current_locale.toString();
				localeFound = true;
				Log.message("localeFound retString == " + retString);
				break;
			}
		}
		if(!localeFound){
			for(String str : SUPPORTEDLOCALE) {
				if(str.equals(current_locale.getLanguage())) {
					retString = current_locale.getLanguage();
					Log.message("localeNotFound retString == " + retString);
					break;
				}
			}
		}
		
		return retString;
	}
}
